package com.hunktimes.wholesale.ui.pages

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hunktimes.wholesale.R
import com.hunktimes.wholesale.base.BasePageFragment
import com.hunktimes.wholesale.base.BaseViewModel
import com.hunktimes.wholesale.databinding.FragmentSearchResultBinding
import com.hunktimes.wholesale.widget.FlowLayoutManager

/**
 * Author: Delete
 * Date: 2020/7/27 14:36
 * Description:
 *
 */
class SearchResultFragment : BasePageFragment(R.layout.fragment_search_result) {
    lateinit var viewBinding: FragmentSearchResultBinding
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewBinding = FragmentSearchResultBinding.bind(view)
    }

    override fun onStart() {
        super.onStart()
        initGoodsTypeTags()
        initGoodsList()
    }

    val goodsTypeTagAdapter = GoodsTypeTagAdapter()
    fun initGoodsTypeTags() {
        //val goodsTypeTagLm = FlowLayoutManager()
        val goodsTypeTagLm = GridLayoutManager(requireContext(), 4)
        goodsTypeTagLm.orientation = GridLayoutManager.VERTICAL
        viewBinding.goodsTypeTagRcv.layoutManager = goodsTypeTagLm
        viewBinding.goodsTypeTagRcv.adapter = goodsTypeTagAdapter
        val data = mutableListOf<String>()
        data.add("全部")
        data.add("推薦")
        data.add("熱賣")
        data.add("新品")
        goodsTypeTagAdapter.data = data

    }

    val goodsAdapter = GoodsAdapter()
    fun initGoodsList() {
        val goodsLm = LinearLayoutManager(requireContext())
        goodsLm.orientation = LinearLayoutManager.VERTICAL
        viewBinding.goodsRcv.layoutManager = goodsLm
        viewBinding.goodsRcv.adapter = goodsAdapter

        val data = mutableListOf<String>()
        for (i in 1..4) {
            data.add("購物車$i")
        }
        goodsAdapter.data = data
    }
}

class GoodsTypeTagAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_goods_type_tag) {
    override fun convert(holder: BaseViewHolder, item: String) {
        holder.setText(R.id.item_goods_type_tag_tv, item)
    }
}

class GoodsAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_goods) {
    override fun convert(holder: BaseViewHolder, item: String) {
    }
}